/**
 * Created by WT-SUN on 2017/4/20.
 */

$(function () {
    if (arrForbid.length>0){
        occforbidTb();
    }else {
        $("#occforbidTbDiv").hide();
    }
    if(arrDoubt.length>0){
        occdoubtTb();
    }else {
        $("#occdoubtTbDiv").hide();
    }
    if(arrOther.length>0){
        occotherTb();
    }else {
        $("#occotherTbDiv").hide();
    }
    $("#danwei").textbox('setValue', danweiName).textbox('setText', danweiName);
    $("#zyweihai").textbox('setValue', phyHarmIdsName).textbox('setText', phyHarmIdsName);
    /**
     * 职业病诊断
     */
    if (arrphyDiagnosis.length>0){
        $("#occZdTbDiv").show();
        occZdTb();
    }else {
        $("#occZdTbDiv").hide();
    }
    /**
     * 调岗
     */
    if($("#conclusionTgy").is(":checked")) {
        $("#tiaogangDiv").show();
    }else {
        $("#tiaogangDiv").hide();
    }
    /**
     * 职业病诊断
     */
    if($("#conclusionZdy").is(":checked")) {
        $("#occZdTbDiv").show();
        occZdTb();
    }else {
        $("#occZdTbDiv").hide();
    }
    attachFileRowEvent('occZdTb', ROOT_PATH + '/occupationalHealth/phyData/upload.shtml');
    occReviewTb();
});

function occReviewTb() {
    $('#occReviewTb').datagrid({
        fitColumns: true,
        idField: 'id',
        rownumbers: true,
        data:arrReview,
        sortOrder: true,
        singleSelect: true,
        striped: true,
        fit: false,
        height: 200,
        columns: [[
            {
                field: 'id', title: 'id', hidden:true,width: 20
            },
            {field: 'phyId', title: 'phyId', hidden:true,width: 100},
            {field: 'reConclusionName', title: '复查结论', width: 100},
            {field: 'diseasesName', title: '职业病名称', width: 100},
            {field: 'forbidWork', title: '禁忌作业', width: 80},
            {field: 'diagnosisDate', title: '诊断日期', width: 100},
            {field: 'serviceName', title: '诊断单位', width: 100},
            {field: 'remarks', title: '备注', width: 100},
            {field: 'addTime', title: '登记日期', width: 80}
        ]],
    });
}
function occZdTb() {
    $('#occZdTb').datagrid({
        fitColumns: true,
        //idField: 'id',
        rownumbers: true,
        data:arrphyDiagnosis,
        sortOrder: true,
        singleSelect: true,
        fit: false,
        height: 200,
        columns: [[
            {
                field: 'id', title: 'id', hidden:true,width: 20,
            },
            {
                field: 'oldid', title: 'oldid', hidden:true,width: 20,
            },
            {field: 'phyId', title: 'phyId', hidden:true,width: 100},
            {field: 'conclusionName', title: '诊断结论', width: 100},
            {field: 'diseasesName', title: '职业病名称', width: 100},
            {field: 'diagnosisDate', title: '诊断日期', width: 100},
            {field: 'forbidWork', title: '禁忌作业', width: 80},
            {field: 'serviceName', title: '诊断单位', width: 100},
            {field: 'remarks', title: '备注', width: 100},
            {field: 'startTime', title: '开始接触时间', width: 100},
            {field: 'workYears', title: '工龄', width: 100},
            {field: 'zgSituation', title: '转归情况', width: 80},
            {
                field: 'accessory', title: '附件', width: 50, align: 'center', formatter: function (value, row, index) {
                return '<a id="occZdTb_btn_file_' + row.oldid + '" href="javascript:void(0)" class="easyui-linkbutton text-primary" plain="true">附件</a> ';
            }}
        ]],
    });
}

/**
 * 职业禁忌
 */
function occforbidTb() {
    $('#occforbidTb').datagrid({
        fitColumns: true,
        //pagination: true,
        idField: 'id',
        data:arrForbid,
        rownumbers: true,
        sortOrder: true,
        singleSelect: true,
        striped: true,
        fit: false,
        height: 200,
        columns: [[
            {
                field: 'id',
                checkbox: true
            },
            {field: 'forbidName', title: '职业禁忌证名称', width: 100},
            {field: 'forbidWork', title: '禁忌作业', width: 100},
            {field: 'remarks', title: '备注', width: 100}
        ]],
    });
}
/**
 * 疑似职业病
 */
function occdoubtTb() {
    $('#occdoubtTb').datagrid({
        fitColumns: true,
        data:arrDoubt,
        //pagination: true,
        idField: 'id',
        rownumbers: true,
        sortOrder: true,
        singleSelect: true,
        striped: true,
        fit: false,
        height: 200,
        columns: [[
            {
                field: 'id',
                checkbox: true
            },
            {field: 'diseasesName', title: '职业病名称', width: 100},
            {field: 'diseasesCode', title: '编码', width: 100},
            {field: 'remarks', title: '备注', width: 100}
        ]]
    });
}
/**
 * 其它疾病或异常
 */
function occotherTb() {
    $('#occotherTb').datagrid({
        fitColumns: true,
        idField: 'id',
        data:arrOther,
        rownumbers: true,
        sortOrder: true,
        singleSelect: true,
        striped: true,
        fit: false,
        height: 200,
        columns: [[
            {
                field: 'id',
                checkbox: true
            },
            {field: 'diseasesName', title: '疾病名称', width: 100},
            {field: 'remarks', title: '备注', width: 100}
        ]]
    });
}
var attachFileRowEvent = function (dataGridId, url) {
    $('body').on('click', '[id^=' + dataGridId + '_btn_file_]', function () {
        var id = this.id.replace(dataGridId + '_btn_file_', '');
        var uploadUserId = $(':input[name=uploadUserId]').val();
        var packageKey = 'occZdTbFile';
        var layerIndex = parent.layer.open({
            type: 2,
            title: '上传附件',
            area: ['500px', '300px'],
            content: ROOT_PATH + '/accessory/fileUpload.shtml?resourceId=' + $.getQueryParam('resourceId') + '&uploadUserId=' + uploadUserId + '&businessId=' + id + '&packageKey=' + packageKey+'&write=readonly',
        });
    });
};

